// 导入登录接口函数
import { loginApi } from "@/api/user";
export default {
  namespaced: true,
  state() {
    return {
      refresh_token: "",
      token: "",
    };
  },
  mutations: {
    setToken: (state, token) => {
      state.token = token;
    },
    setRefreshToken: (state, refreshtoken) => {
      state.refresh_token = refreshtoken;
    },
    // 退出登录清除Token
    removeToken: (state) => {
      state.token = "";
    },
    removeRefreshToken: (state) => {
      state.refresh_token = "";
    },
  },
  actions: {
    loginAction: async ({ commit }, loginForm) => {
      const resp = await loginApi(loginForm);
      //   console.log(resp);
      commit("setToken", resp.data.token);
      commit("setRefreshToken", resp.data.refresh_token);
    },
    // 退出登录（包装多个mutation）
    logoutAction: ({ commit }) => {
      commit("removeToken");
      commit("removeRefreshToken");
    },
  },
};
